home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15451 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  66 lines

  1. Path: news.cuny.edu!not-for-mail
  2. From: dzielins@its.brooklyn.cuny.edu (Daniel Zielinski)
  3. Newsgroups: comp.lang.c
  4. Subject: help with queue
  5. Date: 19 Apr 1996 00:11:45 -0400
  6. Organization: Brooklyn College
  7. Message-ID: <4l73q1$148@itsop2.its.brooklyn.cuny.edu>
  8. NNTP-Posting-Host: itsop2.its.brooklyn.cuny.edu
  9.  
  10. Could anybody help me with QUEUE structure? It's node based.
  11. It seems that assert function fails (It's in the removeQueue function)
  12. Whenever I try to remove something from a QUEUE I get:
  13.  line 31 in QUEUE.c assert failed.
  14. Any clues on what I'm doing wrong would be apriciated.
  15.  
  16. this is QUEUE.c     
  17.  
  18.  
  19.  
  20. #include "QUEUE.h"
  21. #include <assert.h>
  22. #include <stdio.h>
  23.  
  24. void
  25. insertQueue(Queue *qp,DataType d) {
  26.     Node *np=newNode();
  27.  
  28.     setDataNode(np,d);
  29.     qp->rear=np;
  30.     if (qp->front==NULL)
  31.         qp->front=np;
  32.     else
  33.         qp->rear->next=np;
  34. }
  35.  
  36. int
  37. emptyQueue(Queue q) {
  38.     assert((q.front==NULL && q.rear==NULL) || (q.front!=NULL && 
  39.         q.rear!=NULL)); 
  40.     return q.front==NULL;
  41. }
  42.  
  43. DataType
  44. removeQueue(Queue *qp) {
  45.     Node *np;
  46.     DataType d;
  47.  
  48.     assert(!emptyQueue(*qp));     <-------- THIS IS THE LINE    
  49.     np=qp->front;
  50.     d=np->data;
  51.     qp->front=np->next;
  52.     if (qp->front==NULL)
  53.         qp->rear=NULL;
  54.     deleteNode(np);
  55.     return d;
  56. }
  57.  
  58. void
  59. initQueue(Queue *qp) {
  60.     qp->front=qp->rear=NULL;
  61. }
  62.  
  63.  
  64. thanks
  65.  
  66.